/*
 *    Copyright (c) 2018-2025, cloud All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: cloud
 */
package com.fuyao.cloud.admin.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyao.cloud.message.dto.DocTypeDTO;
import com.fuyao.cloud.admin.api.entity.DocType;
import com.fuyao.cloud.admin.mapper.DocTypeMapper;
import com.fuyao.cloud.admin.service.DocTypeService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 文档配置
 *
 * @author liyue
 * @date 2022-04-24 15:47:04
 */
@Service
public class DocTypeServiceImpl extends ServiceImpl<DocTypeMapper, DocType> implements DocTypeService {

    @Override
    public List<DocTypeDTO> getAllDocTypeOption(QueryWrapper<DocType> queryWrapper) {
        List<DocType> docTypeList = this.list(queryWrapper);
        return docTypeList.stream().map(d -> {
            DocTypeDTO docTypeDTO = new DocTypeDTO();
            BeanUtil.copyProperties(d, docTypeDTO);
            return docTypeDTO;
        }).collect(Collectors.toList());
    }

    @Override
    public DocType getDocTypeByCode(String code) {
        return this.getOne(Wrappers.<DocType>lambdaQuery().eq(DocType::getDocCode, code), Boolean.FALSE);
    }
}
